<template>
  <!-- 智慧工地平台-人员管理 -->
  <popup
    :show="personnelShow"
    title="智慧工地平台-人员管理"
    @onClone="personnelFun"
  >
    <div class="personnelDialog">
      <section class="buttonBox">
        <ul>
          <li
            v-for="(item, index) in buttonList"
            :key="index"
            :class="buttonIndex == index ? 'active' : ''"
            @click="
              buttonIndex = index;
              showPersionList();
            "
          >
            {{ item }}
          </li>
        </ul>
        <ul>
          <li
            v-for="(item, index) in ThreeMonths"
            :key="index"
            :class="dateIndex == index ? 'active' : ''"
            @click="dateIndex = index"
          >
            {{ item }}
          </li>
        </ul>
      </section>
      <div class="titleBox">
        <el-table
          :data="tableData"
          style="width: 100%; height:50px,margin-top: 20px,border: 1px solid #495A79,background: '#104584'"
          :row-style="{ height: 50 + 'px' }"
          :header-cell-style="{
            background: '#104584',
            color: '#fff',
            borderColor: '#495A79',
            height: 50 + 'px',
            padding: 0 + 'px',
          }"
          :cell-style="{
            background: '#0C2451',
            color: '#fff',
            height: 50 + 'px',
            borderColor: '#495A79',
            padding: 6 + 'px',
            cursor: 'pointer',
          }"
          @row-click="rowClick"
        >
          <el-table-column prop="name" label="姓名" width="80">
          </el-table-column>
          <el-table-column prop="sex" label="性别" width="50">
          </el-table-column>
          <el-table-column prop="birthday" label="出生日期" width="90">
          </el-table-column>
          <el-table-column prop="enterpriseName" label="参建单位" width="200">
          </el-table-column>
          <el-table-column prop="workType" label="岗位工种" width="150">
          </el-table-column>
          <el-table-column
            prop="isSafetyQualified"
            label="安全教育是否准入"
            width="100"
          >
            <template slot-scope="scope">
              <span>{{ scope.row.isSafetyQualified == 1 ? "是" : "否" }}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="isAntiepidemicQualified"
            label="防疫措施是否准入"
            width="100"
          >
            <template slot-scope="scope">
              <span>{{
                scope.row.isAntiepidemicQualified == 1 ? "是" : "否"
              }}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="isRulesQualified"
            label="违章历史是否准入"
            width="100"
          >
            <template slot-scope="scope">
              <span>{{ scope.row.isRulesQualified == 1 ? "是" : "否" }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="inOrOut" label="进场或出场" width="100">
            <template slot-scope="scope">
              <span>{{ scope.row.inOrOut == 1 ? "是" : "否" }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="inoutTime" label="进出场时间" width="100">
          </el-table-column>
          <el-table-column prop="coordinateRealtime" label="人员实时坐标">
          </el-table-column>
        </el-table>
      </div>
      <section class="pagination">
        <select v-model="selected" @change="selectChange">
          <option
            v-for="(option, idx) in options"
            :key="idx"
            :value="option.value"
          >
            {{ option.text }}
          </option>
        </select>
        <MoPaging
          :page-index="currentPage"
          :total="count"
          :page-size="pageSize"
          @pageChange="pageChange"
        >
        </MoPaging>
        <div class="pege">
          跳至
          <input type="tel" v-model="page" @blur="inputBlur" />
          页
        </div>
      </section>
    </div>
  </popup>
</template>

<script>
import popup from "../../popup.vue";
import MoPaging from "../mo-paging.vue";
import api from "@/util/api";
import * as dayjs from "dayjs";
export default {
  components: {
    popup,
    MoPaging,
  },
  name: "personnelDialog",
  data() {
    return {
      personnelDialog: ``,
      buttonList: ["登记人数", "场内人数"],
      buttonIndex: 0,
      ThreeMonths: [],
      dateIndex: 0,
      tableData: [],
      page: 1,
      pageSize: 5, //每页显示10条数据
      currentPage: 1, //当前页码
      count: 100, //总记录数,
      selected: 5,
      options: [
        { text: "5条/页", value: 5 },
        { text: "7条/页", value: 7 },
        { text: "9条/页", value: 9 },
      ],
    };
  },
  computed: {
    personnelShow: function () {
      return this.$store.state.personnelShow;
    },
  },
  mounted() {
    this.showPersionList();
  },
  methods: {
    personnelFun(data) {
      let that = this;
      that.$store.dispatch("changeFun", {
        str: "personnelShow",
        cont: data,
      });
    },
    //从page组件传递过来的当前page
    pageChange(page) {
      this.currentPage = page;
      this.page = page;
      this.showPersionList();
    },
    // 每页条数改变
    selectChange() {
      this.pageSize = this.selected;
      this.showPersionList();
    },
    // 当前页改变
    inputBlur() {
      // this.currentPage = this.page
      this.pageChange(+this.page);
    },

    // 时间切换
    getList() {
      if (this.buttonIndex) {
        this.getAcceptanceList();
      } else {
        this.getUnQualifiedList();
      }
    },
    // 该行被点击
    rowClick(row, column, event) {
      console.log("208 row", row);
      console.log("208 column", column);
      console.log("208 event", event);
      this.$store.dispatch('changeFun',{
        str: 'threeLevelShow',
        cont: true
      })
      this.$store.dispatch("changeFun", {
        str: "threeLevel",
        cont: {
          type: 'person',
          id: row.id
        },
      });
    },
    /** API */
    // 大屏二级展示数据:获取相关字典表数据
    getDictroyData() {
      api.getDictroyData({}, (res) => {
        console.log(res);
      });
    },
    // 大屏二级展示数据:所有人员列表，也可查看在场人员列表
    showPersionList() {
      api.showPersionList(
        {
          inOrOut: this.buttonIndex,
          pageNum: this.currentPage,
          pageSize: this.pageSize,
        },
        (res) => {
          console.log(res);
          this.tableData = res.data.list;
          this.count = res.data.total;
        }
      );
    },
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less">
.personnelDialog {
  width: 1200px;
  height: 700px;
  overflow: auto;
  .buttonBox {
    width: 100%;
    height: auto;
    padding-bottom: 30px;
    display: flex;
    justify-content: space-between;
    ul {
      display: flex;
      justify-content: space-between;
      color: #fff;
      li {
        list-style-type: none;
        width: 100px;
        height: 43px;
        background-color: #135ba7;
        border-radius: 4px;
        text-align: center;
        line-height: 43px;
        margin-left: 12px;
      }
      li:nth-child(1) {
        margin: 0;
      }
      .active {
        background-color: #ff891d;
      }
    }
  }
  .titleBox {
    width: 1200px;
    height: 520px;
  }
  .pagination {
    width: fit-content;
    margin: 0 auto;
    padding-top: 10px;
    select {
      width: 95px;
      height: 40px;
      border: 1px solid #e6ecf3;
      border-radius: 2px;
      margin-left: 12px;
      padding-left: 12px;
      line-height: 40px;
      font-size: 15px;
      text-align: center;
      color: #fff;
      overflow: hidden;
      background-color: #00000000;
      option {
        color: #000;
      }
    }
    .pege {
      display: inline-block;
      color: #fff;
      font-size: 15px;
      input {
        width: 63px;
        height: 40px;
        color: #fff;
        border: 1px solid #e6ecf3;
        border-radius: 2px;
        padding-left: 6px;
        background-color: #00000000;
        box-sizing: border-box;
      }
    }
  }
  .el-table--border::after,
  .el-table--group::after,
  .el-table::before {
    background-color: #495a79 !important;
  }
}
</style>

